#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    vector<vector<int>> threeSum(vector<int>& nums) {
        sort(nums.begin(), nums.end()); // 排序
        vector<vector<int>> ret;        // 存结果

        for (int i = 0; i < nums.size() - 2;)
        {
            int for_num = -nums[i];
            int j = i + 1, k = nums.size() - 1;
            while (j < k)
            {
                if (nums[j] + nums[k] < for_num)
                {
                    j++;
                }
                else if (nums[j] + nums[k] > for_num)
                {
                    k--;
                }
                else
                {
                    ret.push_back({ nums[i],nums[j],nums[k] });
                    j++;
                    k--;
                    while (nums[j] == nums[j - 1] && j < k)
                    {
                        j++;
                    }
                    while (nums[k] == nums[k + 1] && j < k)
                    {
                        k--;
                    }
                }
            }
            i++;
            while (nums[i] == nums[i - 1] && i < nums.size() - 2)
            {
                i++;
            }
        }

        return ret;
    }
};
////////////////////////
class Solution {
public:
    int maxArea(vector<int>& height)
    {
        int left = 0, right = height.size() - 1;
        int ret = 0;
        while (left < right)
        {
            ret = max(ret, min(height[left], height[right]) * (right - left));
            if (height[left] < height[right])
            {
                left++;
            }
            else
            {
                right--;
            }
        }
        return ret;

    }
};
//////////////////////////////
class Solution {
public:
    void moveZeroes(vector<int>& nums)
    {
        for (int i = 0, j = 0; i < nums.size(); i++)
        {
            if (nums[i] != 0)
            {
                swap(nums[i], nums[j++]);
            }
        }
    }
};